package com.study.jdbc.utils;

import java.util.List;

/**
* @Name: PageBean
* @Description: 分页信息类
* @Author: 李超	lc_jack@foxmail.com
* @CreateDate: 2017-2-17 下午3:43:21 
* @Version: V1.0
 */
public class PageBean<T> {
	
	private List<T> records ;  	//显示的分页记录
	private Integer totalRecordsNum ; //总记录数
	private Integer pageSize = 2 ;	//每页显示的记录数
	private Integer totalPagesNum ; 	//总页数
	private Integer startIndex ; //每页开始记录索引
	private Integer currentPageNum ; //当前页码
	private Integer proviousPageNum ; //上一页页码
	private Integer nextPageNum ; //下一页页码
	
	private Integer startPageNum ;	//开始页码
	private Integer endPageNum ; 	//结束页码
	private Integer pageNumCount = 8 ; //显示页码数
	private Integer moveNum = 4 ; //移动页码数
	
	private String url ; //查询记录的servlet请求的url地址
	
	public PageBean(Integer totalRecoedsNum, Integer currentPageNum) {
		this.totalRecordsNum = totalRecoedsNum;
		this.currentPageNum = currentPageNum;
		//计算总页数
		totalPagesNum = (totalRecordsNum % pageSize) == 0 ? (totalRecordsNum / pageSize) : (totalRecordsNum / pageSize + 1) ;
		//计算每页开始记录的的索引
		startIndex = (currentPageNum -1) * pageSize ;
		
		//计算页码
		if(totalPagesNum <= pageNumCount) {
			startPageNum = 1 ;
			endPageNum = totalPagesNum ;
		} else {
			startPageNum = pageNumCount - moveNum ;
			endPageNum = pageNumCount + moveNum ;
			if(startPageNum < 1) {
				startPageNum = 1 ;
				endPageNum = startPageNum + pageNumCount -1 ;
			}
			if(endPageNum > totalPagesNum) {
				endPageNum = totalPagesNum ;
				startPageNum = totalPagesNum - moveNum ;
			}
		}
	}

	public List<T> getRecords() {
		return records;
	}

	public void setRecords(List<T> records) {
		this.records = records;
	}

	public Integer getTotalRecordsNum() {
		return totalRecordsNum;
	}

	public void setTotalRecordsNum(Integer totalRecordsNum) {
		this.totalRecordsNum = totalRecordsNum;
	}

	public Integer getPageSize() {
		return pageSize;
	}

	public void setPageSize(Integer pageSize) {
		this.pageSize = pageSize;
	}

	public Integer getTotalPagesNum() {
		return totalPagesNum;
	}

	public void setTotalPagesNum(Integer totalPagesNum) {
		this.totalPagesNum = totalPagesNum;
	}

	public Integer getStartIndex() {
		return startIndex;
	}

	public void setStartIndex(Integer startIndex) {
		this.startIndex = startIndex;
	}

	public Integer getCurrentPageNum() {
		return currentPageNum;
	}

	public void setCurrentPageNum(Integer currentPageNum) {
		this.currentPageNum = currentPageNum;
	}

	public Integer getProviousPageNum() {
		proviousPageNum = (currentPageNum - 1) > 0 ? (currentPageNum - 1) : 1 ;
		return proviousPageNum ;
	}

	public void setProviousPageNum(Integer proviousPageNum) {
		this.proviousPageNum = proviousPageNum;
	}

	public Integer getNextPageNum() {
		nextPageNum = (currentPageNum + 1) > totalPagesNum ? totalPagesNum : (currentPageNum + 1) ;
		return nextPageNum ;
	}

	public void setNextPageNum(Integer nextPageNum) {
		this.nextPageNum = nextPageNum;
	}

	public Integer getStartPageNum() {
		return startPageNum;
	}

	public void setStartPageNum(Integer startPageNum) {
		this.startPageNum = startPageNum;
	}

	public Integer getEndPageNum() {
		return endPageNum;
	}

	public void setEndPageNum(Integer endPageNum) {
		this.endPageNum = endPageNum;
	}

	public Integer getPageNumCount() {
		return pageNumCount;
	}

	public void setPageNumCount(Integer pageNumCount) {
		this.pageNumCount = pageNumCount;
	}

	public Integer getMoveNum() {
		return moveNum;
	}

	public void setMoveNum(Integer moveNum) {
		this.moveNum = moveNum;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}
	
}
